package com.example.demo.shiro;

import org.apache.shiro.authz.Permission;
import org.apache.shiro.util.AntPathMatcher;
import org.apache.shiro.util.PatternMatcher;

public class UrlPermission implements Permission {
    private String url;

    public UrlPermission(String url) {
        this.url = url;
    }

    @Override
    public boolean implies(Permission permission) {
        if (!(permission instanceof UrlPermission)) {
            return false;
        }
        UrlPermission urlPermission = (UrlPermission) permission;
        PatternMatcher patternMatcher = new AntPathMatcher();
        //this.url在Realm的授权方法中注入的url，也就是来自数据库
        //urlPerimission.url来自浏览器访问的链接
        boolean matches = patternMatcher.matches(this.url, urlPermission.url);
        System.out.println("matches:"+matches);
        return  matches;
    }
}
